#include <iostream>
#include <string>
using namespace std;

int dfs(int n)
{
    if (n / 10 == 0)
        return n;
    int tmp = 0;
    while (n)
    {
        tmp += n % 10;
        n /= 10;
    }
    return dfs(tmp);
}
int main() {
    string s;
    while (cin >> s)
    {
        int n = 0;
        for (auto c : s) n += c - '0';
        cout << dfs(n) << endl;
    }
    return 0;
}